package cn.sciento.starter.social.wechat.config;

import cn.sciento.starter.social.core.common.configurer.SocialConnectionFactoryBuilder;
import cn.sciento.starter.social.core.common.connect.SocialApiAdapter;
import cn.sciento.starter.social.core.common.connect.SocialConnectionFactory;
import cn.sciento.starter.social.core.common.connect.SocialServiceProvider;
import cn.sciento.starter.social.core.common.connect.SocialTemplate;
import cn.sciento.starter.social.core.common.constant.ProviderEnum;
import cn.sciento.starter.social.core.provider.Provider;
import cn.sciento.starter.social.wechat.connection.WechatApiAdapter;
import cn.sciento.starter.social.wechat.connection.WechatConnectionFactory;
import cn.sciento.starter.social.wechat.connection.WechatServiceProvider;
import cn.sciento.starter.social.wechat.connection.WechatTemplate;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WechatSocialBuilder implements SocialConnectionFactoryBuilder {
  public String getProviderId() {
    return ProviderEnum.wechat.name();
  }
  
  public SocialConnectionFactory buildConnectionFactory(Provider provider) {
    String URL_AUTHORIZE = "https://open.weixin.qq.com/connect/qrconnect";
    String URL_GET_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token";
    String URL_GET_USER_INFO = "https://api.weixin.qq.com/sns/userinfo";
    provider.setAuthorizeUrl("https://open.weixin.qq.com/connect/qrconnect");
    provider.setAccessTokenUrl("https://api.weixin.qq.com/sns/oauth2/access_token");
    provider.setUserInfoUrl("https://api.weixin.qq.com/sns/userinfo");
    WechatApiAdapter apiAdapter = new WechatApiAdapter();
    WechatTemplate template = new WechatTemplate(provider);
    WechatServiceProvider serviceProvider = new WechatServiceProvider(provider, (SocialTemplate)template);
    return (SocialConnectionFactory)new WechatConnectionFactory(provider, (SocialServiceProvider)serviceProvider, (SocialApiAdapter)apiAdapter);
  }
}
